package com.zgz.underwrite.util;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 
 * @author zgz
 * 
 */
public class Page implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = -4066248446491730077L;

	public static int DEFAULT_PAGE_SIZE = 15;//默认页面大小
	
	private long totalCount; // 总记录数
	private long pageSize; // 当前页面容量
	private long currentPageNo = 1; //当前页数
	private long totalPageCount; // 总页数
	private long start; // 当前页第一条数据在数据集中的位置,从0开始
	private List<?> list; // 当前页中存放的记录
	
	private String pageOpera;

	public void setCurrentPageNo(long currentPageNo) {
		this.currentPageNo = currentPageNo;
	}
	
	public long getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(long totalCount) {
		this.totalCount = totalCount;
	
	}
	
	public long getPageSize(){
		return this.pageSize;
	}
	
	public void setPageSize(long pageSize) {
		this.pageSize = pageSize;
	}

	public long getTotalPageCount(){
		if(this.getTotalCount() % DEFAULT_PAGE_SIZE == 0){
			return this.getTotalCount()/DEFAULT_PAGE_SIZE;
		}else{
			return this.getTotalCount()/DEFAULT_PAGE_SIZE + 1;
		}
	}
	
	public long getCurrentPageNo(){
		return this.currentPageNo;
	}
	
	public long getStart(){
		if(this.getPageSize() < DEFAULT_PAGE_SIZE){
			return this.getTotalCount() - this.pageSize;
		}
		else{
			return (this.getCurrentPageNo()-1)*DEFAULT_PAGE_SIZE ;
		}
	}

	
	public Page() {
		this(0, 0, DEFAULT_PAGE_SIZE, new ArrayList<Object>());
	}

	/**
	 * 
	 * @param start
	 *            本页数据在数据库中的起始位置
	 * @param totalSize
	 *            数据库中总记录条数
	 * @param pageSize
	 *            本页容量
	 * @param data
	 *            本页包含的数据
	 */
	public Page(long start, long totalSize, int pageSize, List<?> list) {
		this.pageSize = pageSize;
		this.start = start;
		this.totalCount = totalSize;
		this.list = list;
	}


	/**
	 * 该页是否有下一页.
	 */
	public boolean hasNextPage() {
		return this.getCurrentPageNo() < this.getTotalPageCount();
	}

	/**
	 * 该页是否有上一页.
	 */
	public boolean hasPreviousPage() {
		return this.getCurrentPageNo() > 1;
	}


	public void setList(List<?> list) {
		this.list = list;
	}

	public List<?> getList() {
		return list;
	}

	public void setTotalPageCount(long totalPageCount) {
		this.totalPageCount = totalPageCount;
	}

	public void setStart(long start) {
		this.start = start;
	}

	public void setPageOpera(String pageOpera) {
		this.pageOpera = pageOpera;
	}

	public String getPageOpera() {
		return pageOpera;
	}

}